package action;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;

import pageModel.Json;
import pageModel.ShopList;
import service.ShopListServiceI;

import com.opensymphony.xwork2.ModelDriven;
@Namespace("/")
@Action(value="shopListAction")
public class ShopListAction extends BaseAction implements ModelDriven<ShopList>{
ShopList shopList=new ShopList();
private ShopListServiceI shopListService;

	public ShopListServiceI getShopListService() {
	return shopListService;
}
@Autowired
public void setShopListService(ShopListServiceI shopListService) {
	this.shopListService = shopListService;
}

	@Override
	public ShopList getModel() {
		return shopList;
	}
public void save(){
	    Json j = new Json();	
		shopListService.saveOrUpdate(shopList.getTid(),shopList.getCodes(),shopList.getAmounts(),shopList.getNprices());
		j.setSuccess(true);
	    super.writeJson(j);
}
public void show(){
    super.writeJson(shopListService.show(shopList));
}
public void updateInventory(){
	Json j = new Json();
	shopListService.updateInventory(shopList.getCodes(), shopList.getAmounts());
	j.setSuccess(true);
	super.writeJson(j);
}
public void outputReceipt(){
	super.writeJson(shopListService.outputReceipt(shopList));
}
}
